import { useState } from "react";

export function useCountDown(initialTime = 60) {
  const [count, setCount] = useState(initialTime);


  const startCountDown = () => {
    const timer = setInterval(() => {
      setCount(prev => {
        if(prev <= 1) {
          clearInterval(timer)
          setCount(initialTime)
        }
        return prev - 1
      })
    }, 1000)
  }

  return { count,  startCountDown } 
}